﻿using System;
using System.Windows.Forms;
using Microsoft.Office.Interop.PowerPoint;
using Microsoft.Office.PowerPoint.STAMP.Core;
using Microsoft.Office.PowerPoint.STAMP.Presenter;
using Microsoft.Office.PowerPoint.STAMP.View;
using Application = Microsoft.Office.Interop.PowerPoint.Application;

namespace Microsoft.Office.PowerPoint.STAMP
{
    /// <summary>
    /// Captions import form.
    /// </summary>
    public partial class AddCaptionsImport : Form, IImportView, IRenderView
    {
        private ImportPresenter _presenter;

        /// <summary>
        /// Default Constructor for AddCaptionsImport
        /// </summary>
        public AddCaptionsImport()
        {
            InitializeComponent();

            _presenter = new ImportPresenter(this);
        }

        private void AddCaptionsImport_Load(object sender, EventArgs e)
        {
            ShowFileDialog(sender, e);
        }

        private void btnBrowse_Click(object sender, EventArgs e)
        {
            ShowFileDialog(sender, e);
        }

        private void ShowFileDialog(object sender, EventArgs e)
        {
            var openFileDialog = new OpenFileDialog()
            {
                Filter = "TimedText Markup|*.xml|All files|*.*",
                FilterIndex = 0,
                DefaultExt = "*.xml"
            };

            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                FilePath = openFileDialog.FileName;
            }
            else
            {
                Close();
            }
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        public Application Application
        {
            get { return Globals.ThisAddIn.Application; }
        }

        public Slide Slide
        {
            get { return Application.ActiveWindow.View.Slide; }
        }

        public Shape Shape
        {
            get { return Application.ActiveWindow.Selection.ShapeRange[1]; }
        }

        public ClosedCaptionsList CaptionsList { get; set; }

        private void btnOk_Click(object sender, EventArgs e)
        {
            _presenter.LoadCaptionsListFromFile();
        }

        public string FilePath
        {
            get { return txtTtmlLocation.Text; }
            set { txtTtmlLocation.Text = value; }
        }

        public string Extention { get; set; }

        public bool EditRequired
        {
            get { return cbEditCaptions.Checked; }
        }
    }
}